<?php
/**
 * Created by PhpStorm.
 * User: dy
 * Date: 2019/12/19
 * Time: 10:27
 */
namespace app\admin\controller;
use app\common\controller\BackendController;
use think\facade\Db;
use think\facade\View;
use util\ArrayUtil;

class Home extends BackendController
{
    protected $noNeedCheck = [
        'index'
    ];
    public function console(){
        return view();
    }

    public function index(){
        $pv_list = Db::name('exe_log')
            ->cache('pv_list_cache',86400)
            ->field('FROM_UNIXTIME(create_time,"%Y-%m-%d %H") as time,COUNT(*) as count')
            ->group('time')
            ->order('time asc')
            ->select();
        $uv_list = Db::name('exe_log')
            ->cache('uv_list_cache',86400)
            ->field('FROM_UNIXTIME(create_time,"%Y-%m-%d %H") as time,COUNT(distinct(ip)) as count')
            ->group('time')
            ->order('time asc')
            ->select();
        $browser_list = Db::name('exe_log')
            ->cache('browser_list_cache',86400)
            ->field('COUNT(*) as value,browser as name')
            ->group('browser')
            ->select();
        $pv_data = ArrayUtil::instance()->array_extract($pv_list,'count');
        $uv_data = ArrayUtil::instance()->array_extract($uv_list,'count');
        $time = ArrayUtil::instance()->array_extract($pv_list,'time');
        $browser_x = ArrayUtil::instance()->array_extract($browser_list,'name');
        $system_info_mysql = Db::query("select version() as v;");

        // 系统信息
        $data['version']     = SYS_VERSION;
        $data['think_version']  = $this->app->version();
        $data['os']             = PHP_OS;
        $data['software']       = $_SERVER['SERVER_SOFTWARE'];
        $data['mysql_version']  = $system_info_mysql[0]['v'];
        $data['upload_max']     = ini_get('upload_max_filesize');
        $data['php_version']    = PHP_VERSION;

        // 产品信息
        $data['product_name']   = 'tp6study';
        $data['author']         = 'dy';
        $data['website']        = '暂无';
        View::assign('data',$data);
        View::assign('pv_data',$pv_data);
        View::assign('time',$time);
        View::assign('uv_data',$uv_data);
        View::assign('browser_x',$browser_x);
        View::assign('browser_list',$browser_list);
        return view();
    }

    public function homepage1(){
        return view();
    }
}